package com.maple.p2pclient.qr;

import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import com.google.zxing.BarcodeFormat;
import com.journeyapps.barcodescanner.BarcodeEncoder;
import com.maple.p2pclient.R;
import com.maple.p2pclient.utils.LogUtils;

import androidx.appcompat.app.AppCompatActivity;

public class QRCodeActivity extends AppCompatActivity {

    private ImageView ivQR;
    private Button btnQR,btnScan;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_qrcode);
        btnQR = findViewById(R.id.btn_qr);
        btnScan = findViewById(R.id.btn_scan);
        ivQR = findViewById(R.id.iv_qr);

        btnQR.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                try {
                    BarcodeEncoder barcodeEncoder = new BarcodeEncoder();
                    Bitmap qrBitmap = barcodeEncoder.encodeBitmap("content", BarcodeFormat.QR_CODE, 400, 400);
//                    ImageView imageViewQrCode = (ImageView) findViewById(R.id.qrCode);
//                    imageViewQrCode.setImageBitmap(bitmap);
                    ivQR.setImageBitmap(qrBitmap);
                } catch(Exception e) {
                    LogUtils.logGGQ("生成QR异常：" +e.getMessage());
                }
            }
        });

        btnScan.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
    }
}